;/////////////////////////////////////////////////////////////;
;                                                             ;
;                 SimpleDX11 Light Procedures                 ;
;                                                             ;
;                                                             ;
;                   (c) 2013 SimpleDX Team                    ;
;                                                             ;
;                         License: MIT                        ;
;                                                             ;
;/////////////////////////////////////////////////////////////;




;-//    Private structures    //
Structure LightConstantBuffer
  AmbientColor.D3DXCOLOR
  DiffuseColor.D3DXCOLOR
  Direction.XMFLOAT3
	SpecularPower.f
	SpecularColor.D3DXCOLOR
EndStructure

Structure Light_Template
  *vTable
  *p.Model
  
  SpecularPower.f
	SpecularColor.D3DXCOLOR
  AmbientColor.D3DXCOLOR
  DiffuseColor.D3DXCOLOR
  Direction.XMFLOAT3
  Type.l
EndStructure


;-//    Constructor    //
Procedure New_Light()
  Protected *this.Light_Template
 
  *this = AllocateMemory(SizeOf(Light_Template))
  InitializeStructure(*this, Light_Template)
  
  If *this
    *this\vTable = ?Light_Class    
    *this\p = *this
    
    *this\DiffuseColor\r = 1.0
    *this\DiffuseColor\g = 1.0
    *this\DiffuseColor\b = 1.0
    *this\DiffuseColor\a = 1.0
    *this\Direction\z    = 1.0
    *this\AmbientColor\r = 1.0
    *this\AmbientColor\g = 1.0
    *this\AmbientColor\b = 1.0
    *this\AmbientColor\a = 1.0    

    *this\SpecularPower = 33.0 
    ProcedureReturn *this
  EndIf  
  ProcedureReturn #False
EndProcedure



;-//    Public procedures    //

Procedure Light_SetSpecularColor(*this.Light_Template, ColorValue.l)
  Protected *Color.D3DXCOLOR = AllocateMemory(SizeOf(D3DXCOLOR)) 
  GetColorFloats()
  
  *this\SpecularColor\r = *Color\r  
  *this\SpecularColor\g = *Color\g  
  *this\SpecularColor\b = *Color\b  
  *this\SpecularColor\a = *Color\a 
  FreeMemory(*Color)
EndProcedure

Procedure Light_SetSpecularPower(*this.Light_Template, Power.f)
  *this\SpecularPower = Power  
EndProcedure

Procedure Light_SetAmbientColor(*this.Light_Template, ColorValue.l)
  Protected *Color.D3DXCOLOR = AllocateMemory(SizeOf(D3DXCOLOR)) 
  GetColorFloats()  
  *this\AmbientColor\r = *Color\r  
  *this\AmbientColor\g = *Color\g  
  *this\AmbientColor\b = *Color\b  
  *this\AmbientColor\a = *Color\a  
  FreeMemory(*Color)
EndProcedure

Procedure Light_SetDiffuseColor(*this.Light_Template, ColorValue.l)
  Protected *Color.D3DXCOLOR = AllocateMemory(SizeOf(D3DXCOLOR)) 
  GetColorFloats()  
  *this\DiffuseColor\r = *Color\r  
  *this\DiffuseColor\g = *Color\g  
  *this\DiffuseColor\b = *Color\b  
  *this\DiffuseColor\a = *Color\a  
  FreeMemory(*Color)
EndProcedure

Procedure Light_SetDirection(*this.Light_Template, x.f, y.f, z.f)
  *this\Direction\x = x
  *this\Direction\y = y
  *this\Direction\z = z
EndProcedure

Procedure Light_GetSpecularPower(*this.Light_Template)
  ProcedureReturn *this\SpecularPower 
EndProcedure

Procedure Light_GetSpecularColor(*this.Light_Template)
  ProcedureReturn *this\SpecularColor  
EndProcedure

Procedure Light_GetAmbientColor(*this.Light_Template)
  ProcedureReturn *this\AmbientColor  
EndProcedure

Procedure Light_GetDiffuseColor(*this.Light_Template)
  ProcedureReturn *this\DiffuseColor  
EndProcedure

Procedure Light_GetDirection(*this.Light_Template)
  ProcedureReturn *this\Direction
EndProcedure



Procedure Light_Release(*this.Light_Template)
  FreeMemory(*this)
EndProcedure

;-//    Private procedures    //

;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;-//    DataSection    //
DataSection
  Light_Class: 
  Data.i @Light_SetSpecularColor()
  Data.i @Light_SetSpecularPower()
  Data.i @Light_SetAmbientColor()
  Data.i @Light_SetDiffuseColor()
  Data.i @Light_SetDirection()  
  Data.i @Light_GetSpecularColor()
  Data.i @Light_GetSpecularPower()  
  Data.i @Light_GetAmbientColor()
  Data.i @Light_GetDiffuseColor()
  Data.i @Light_GetDirection()
  Data.i @Light_Release()
EndDataSection
; IDE Options = PureBasic 5.20 beta 14 LTS (Windows - x64)
; CursorPosition = 11
; Folding = ---
; EnableXP
; EnableCompileCount = 0
; EnableBuildCount = 0